"""
 -*- coding: utf-8-*-
 @File: page_home.py
 @Author: chen
 @time: 2023/09/10/ 17:25
"""
import time

import allure
from selenium.webdriver.common.by import By

from dev.page_login import LoginPage
from dev.page_base import PageBase
from tools.record_log import logger


# 首页
class HomePage(PageBase):
    __BUTTON_ADD_MEMBER = (By.XPATH, '//*[text()="添加成员"]')
    __BUTTON_CONTACTS = (By.XPATH, '//*[text()="通讯录"]')

    def goto_contact_list(self):
        """点击通讯录按钮，进入通讯录页面"""
        with allure.step(f"等待通讯录按钮{self.__BUTTON_CONTACTS}可点击"):
            logger.info(f"等待通讯录按钮{self.__BUTTON_CONTACTS}可点击")
            self.wait_until_clickable(self.__BUTTON_CONTACTS)
        with allure.step(f"点击通讯录按钮{self.__BUTTON_CONTACTS}"):
            logger.info(f"点击通讯录按钮{self.__BUTTON_CONTACTS}")
            self.do_click(self.__BUTTON_CONTACTS)
        from dev.page_contact_list import ContactListPage
        logger.info("成功进入通讯录页面")
        return ContactListPage(self.driver)

    def goto_add_member(self):
        """点击添加成员按钮，进人添加成员页面"""
        with allure.step(f"等待添加成员按钮{self.__BUTTON_ADD_MEMBER}可点击"):
            logger.info(f"等待添加成员按钮{self.__BUTTON_ADD_MEMBER}可点击")
            self.wait_until_clickable(self.__BUTTON_ADD_MEMBER)
        with allure.step(f"点击添加成员按钮{self.__BUTTON_ADD_MEMBER}"):
            logger.info(f"点击添加成员按钮{self.__BUTTON_ADD_MEMBER}")
            self.do_click(self.__BUTTON_ADD_MEMBER)

        from dev.page_add_member import AddMemberPage
        logger.info("进入添加成员页面")
        return AddMemberPage(self.driver)

    pass


if __name__ == '__main__':
    cur_page = LoginPage().goto_login().login()
    # cur_page.goto_address_book()
    cur_page.goto_add_member()
    time.sleep(5)
